package com.gollum.system.domain.model;

import com.gollum.jpa.domain.HertherBaseEnity;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.List;

/**
 * 角色 model
 *
 * @author Herther
 * @version 1.0.0
 * @ClassName SysRole.java
 * @createTime 2022年08月07日 15:17:00
 */
@Getter
@Setter
@AllArgsConstructor
@Accessors(chain=true)
@NoArgsConstructor
@Entity
@Table(name = "sys_role")
@EntityListeners(AuditingEntityListener.class)
public class SysRole extends HertherBaseEnity {

    private static final long serialVersionUID = 1L;

    /** 角色名称 */
    @Column(name = "role_name",length = 50)
    private String roleName;

    /** 角色权限 */
    @Column(name = "role_key",length = 50)
    private String roleKey;

    /** 角色排序 */
    @Column(name = "role_sort",length = 50)
    private String roleSort;

    /** 数据范围（1：所有数据权限；2：自定义数据权限；3：本部门数据权限；4：本部门及以下数据权限；5：仅本人数据权限） */
    @Column(name = "data_scope",length = 10)
    private String dataScope;

    /** 菜单树选择项是否关联显示（ 0：父子不互相关联显示 1：父子互相关联显示） */
    @Column(name = "menu_check_strictly",length = 10)
    private String menuCheckStrictly;

    /** 部门树选择项是否关联显示（0：父子不互相关联显示 1：父子互相关联显示 ） */
    @Column(name = "dept_check_strictly",length = 10)
    private String deptCheckStrictly;

    /** 角色状态（0正常 1停用） */
    @Column(name = "status",length = 10)
    private String status;

    /** 角色部门一个角色多个部门 **/
    @OneToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "sys_role_dept",
            joinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "dept_id", referencedColumnName = "id")}
    )
    private List<SysDept> sysDepts;


    @OneToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "sys_role_menu",
            joinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "menu_id", referencedColumnName = "id")}
    )
    private List<SysMenu> menus;

}
